<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{.title}}</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <link href="/static/css/toast.css" rel="stylesheet">
    <link href="/static/css/main.css" rel="stylesheet">
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <!-- 侧边栏 -->
            <nav class="col-md-3 col-lg-2 d-md-block sidebar collapse">
                <div class="position-sticky pt-3">
                    <h5 class="sidebar-heading px-3 mt-4 mb-1 tech-line">
                        <i class="bi bi-cpu"></i> 数据迁移工具
                    </h5>
                    <ul class="nav flex-column">
                        <li class="nav-item">
                            <a class="nav-link" href="/migration">
                                <i class="bi bi-diagram-3"></i> 迁移任务配置
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="/execution">
                                <i class="bi bi-list-task"></i> 任务列表
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="/datasource">
                                <i class="bi bi-hdd-network"></i> 数据源管理
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="/template">
                                <i class="bi bi-filter-circle"></i> 过滤模板
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link active" href="/masking">
                                <i class="bi bi-shield-check"></i> 脱敏规则
                            </a>
                        </li>
                    </ul>
                </div>
            </nav>

            <!-- 主内容区 -->
            <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4 content-area">
                <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                    <h1 class="h2">脱敏规则</h1>
                    <div class="d-flex gap-2">
                        <button class="btn btn-outline-primary" onclick="refreshMaskingRules()">
                            <i class="bi bi-arrow-clockwise"></i> 刷新
                        </button>
                        <button class="btn btn-primary" onclick="showMaskingRuleModal()">
                            <i class="bi bi-plus-circle"></i> 添加规则
                        </button>
                    </div>
                </div>

                <!-- 搜索和筛选 -->
                <div class="search-filters">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="input-group">
                                <span class="input-group-text bg-transparent border-end-0">
                                    <i class="bi bi-search text-muted"></i>
                                </span>
                                <input type="text" class="form-control border-start-0" id="maskingRuleSearch" 
                                       placeholder="搜索规则名称..." onkeyup="filterMaskingRules()">
                            </div>
                        </div>
                        <div class="col-md-3">
                            <select class="form-select" id="maskingRuleTypeFilter" onchange="filterMaskingRules()">
                                <option value="">所有类型</option>
                                <!-- 脱敏类型选项将由JavaScript动态生成 -->
                            </select>
                        </div>
                        <div class="col-md-3">
                            <select class="form-select" id="maskingRuleStatusFilter" onchange="filterMaskingRules()">
                                <option value="">所有状态</option>
                                <option value="enabled">已启用</option>
                                <option value="disabled">已禁用</option>
                            </select>
                        </div>
                    </div>
                </div>

                <!-- 脱敏规则卡片网格 -->
                <div id="maskingRuleGrid" class="row g-4">
                    <!-- 脱敏规则卡片将在这里动态生成 -->
                </div>

                <!-- 空状态 -->
                <div id="emptyMaskingRuleState" class="text-center py-5" style="display: none;">
                    <div class="empty-state">
                        <i class="bi bi-shield-x display-1 text-muted mb-3"></i>
                        <h4 class="text-muted">暂无脱敏规则</h4>
                        <p class="text-muted mb-4">创建您的第一个脱敏规则来保护敏感数据</p>
                        <button class="btn btn-primary" onclick="showMaskingRuleModal()">
                            <i class="bi bi-plus-circle"></i> 添加规则
                        </button>
                    </div>
                </div>

<!-- 脱敏规则管理模态框 -->
<div class="modal fade" id="maskingRuleModal" tabindex="-1">
    <div class="modal-dialog modal-xl">
        <div class="modal-content" style="background: var(--card-bg); border: 1px solid var(--border-color);">
            <div class="modal-header" style="border-bottom: 1px solid var(--border-color);">
                <h5 class="modal-title" id="maskingRuleModalTitle" style="color: var(--primary-color);">添加脱敏规则</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" style="filter: invert(1);"></button>
            </div>
            <div class="modal-body">
                <form id="maskingRuleForm">
                    <input type="hidden" id="maskingRuleId">
                    <div class="mb-3">
                        <label for="ruleName" class="form-label">规则名称 <span class="text-danger">*</span></label>
                        <input type="text" class="form-control" id="ruleName" required>
                    </div>
                    <div class="mb-3">
                        <label for="ruleType" class="form-label">脱敏类型 <span class="text-danger">*</span></label>
                        <select class="form-select" id="ruleType" onchange="setDefaultPattern()" required>
                            <option value="">选择脱敏类型</option>
                            <!-- 脱敏类型选项将由JavaScript动态生成 -->
                        </select>
                    </div>
                    
                    <!-- 模板选择区域 -->
                    <div id="templateSelection" class="mb-3" style="display: none;">
                        <label class="form-label">选择模板</label>
                        <div class="template-buttons" id="templateButtons">
                            <!-- 模板按钮将在这里动态生成 -->
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <label for="rulePattern" class="form-label">正则表达式 <span class="text-danger">*</span></label>
                        <input type="text" class="form-control" id="rulePattern" placeholder="例如: (\d{3})\d{4}(\d{4})" required>
                        <div class="form-text">用于匹配需要脱敏的数据模式</div>
                    </div>
                    <div class="mb-3">
                        <label for="ruleReplace" class="form-label">替换模式 <span class="text-danger">*</span></label>
                        <input type="text" class="form-control" id="ruleReplace" placeholder="例如: $1****$2" required>
                        <div class="form-text">使用$1, $2等引用正则表达式的捕获组</div>
                    </div>
                    <div class="mb-3">
                        <label for="testInput" class="form-label">测试输入</label>
                        <input type="text" class="form-control" id="testInput" placeholder="输入测试数据">
                        <button type="button" class="btn btn-outline-info btn-sm mt-2" onclick="testMaskingRule()">
                            <i class="bi bi-play-circle"></i> 测试脱敏效果
                        </button>
                        <div id="testResult" class="mt-2" style="display: none;">
                            <small class="text-muted">脱敏结果：</small>
                            <div class="alert alert-info py-2" id="testOutput"></div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer" style="border-top: 1px solid var(--border-color);">
                <button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="saveMaskingRule()">
                    <i class="bi bi-save"></i> 保存
                </button>
            </div>
        </div>
    </div>
</div>
            </main>
        </div>
    </div>

    <!-- 弹框容器 -->
    <div class="toast-container" id="toastContainer"></div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="/static/js/common.js"></script>
    <script src="/static/js/masking.js"></script>
</body>
</html>